﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

namespace Studio
{
	// Token: 0x0200057D RID: 1405
	public class VoiceRegistrationList : MonoBehaviour
	{
		// Token: 0x17000455 RID: 1109
		// (get) Token: 0x060023D7 RID: 9175 RVA: 0x000D7738 File Offset: 0x000D5938
		// (set) Token: 0x060023D8 RID: 9176 RVA: 0x000D7740 File Offset: 0x000D5940
		public OCIChar ociChar { get; set; }

		// Token: 0x17000456 RID: 1110
		// (get) Token: 0x060023D9 RID: 9177 RVA: 0x000D774C File Offset: 0x000D594C
		// (set) Token: 0x060023DA RID: 9178 RVA: 0x000D775C File Offset: 0x000D595C
		public bool active
		{
			get
			{
				return base.gameObject.activeSelf;
			}
			set
			{
				if (base.gameObject.activeSelf != value)
				{
					base.gameObject.SetActive(value);
					if (base.gameObject.activeSelf)
					{
						this.InitList();
					}
				}
			}
		}

		// Token: 0x060023DB RID: 9179 RVA: 0x000D7794 File Offset: 0x000D5994
		private void OnClickClose()
		{
			base.gameObject.SetActive(false);
		}

		// Token: 0x060023DC RID: 9180 RVA: 0x000D77A4 File Offset: 0x000D59A4
		private void OnEndEditName(string _text)
		{
			this.buttonSave.interactable = !_text.IsNullOrEmpty();
		}

		// Token: 0x060023DD RID: 9181 RVA: 0x000D77BC File Offset: 0x000D59BC
		private void OnClickSave()
		{
			this.ociChar.voiceCtrl.SaveList(this.inputName.text);
			this.InitList();
		}

		// Token: 0x060023DE RID: 9182 RVA: 0x000D77E0 File Offset: 0x000D59E0
		private void OnClickLoad()
		{
			this.ociChar.voiceCtrl.LoadList(this.listPath[this.select], false);
			this.voiceControl.InitList();
		}

		// Token: 0x060023DF RID: 9183 RVA: 0x000D7810 File Offset: 0x000D5A10
		private void OnClickImport()
		{
			this.ociChar.voiceCtrl.LoadList(this.listPath[this.select], true);
			this.voiceControl.InitList();
		}

		// Token: 0x060023E0 RID: 9184 RVA: 0x000D7840 File Offset: 0x000D5A40
		private void OnClickDelete()
		{
			CheckScene.sprite = this.spriteDelete;
			CheckScene.unityActionYes = new UnityAction(this.OnSelectDeleteYes);
			CheckScene.unityActionNo = new UnityAction(this.OnSelectDeleteNo);
			//Singleton<Scene>.Instance.Load(new Scene.Data
			//{
			//	sceneName = "StudioCheck",
			//	isLoading = false,
			//	isAsync = false,
			//	isFade = false,
			//	isOverlap = false,
			//	isAdd = true
			//});
		}

		// Token: 0x060023E1 RID: 9185 RVA: 0x000D78BC File Offset: 0x000D5ABC
		private void OnSelectDeleteYes()
		{
			Singleton<Scene>.Instance.UnLoad();
			File.Delete(this.listPath[this.select]);
			this.InitList();
		}

		// Token: 0x060023E2 RID: 9186 RVA: 0x000D78E8 File Offset: 0x000D5AE8
		private void OnSelectDeleteNo()
		{
			Singleton<Scene>.Instance.UnLoad();
		}

		// Token: 0x060023E3 RID: 9187 RVA: 0x000D78F8 File Offset: 0x000D5AF8
		private void OnClickSelect(int _no)
		{
			StudioNode studioNode = null;
			if (this.dicNode.TryGetValue(this.select, out studioNode))
			{
				studioNode.select = false;
			}
			this.select = _no;
			if (this.dicNode.TryGetValue(this.select, out studioNode))
			{
				studioNode.select = true;
			}
			if (this.select != -1)
			{
				this.buttonLoad.interactable = true;
				this.buttonImport.interactable = true;
				this.buttonDelete.interactable = true;
			}
		}

		// Token: 0x060023E4 RID: 9188 RVA: 0x000D797C File Offset: 0x000D5B7C
		private void InitList()
		{
			for (int i = 0; i < this.transformRoot.childCount; i++)
			{
				UnityEngine.Object.Destroy(this.transformRoot.GetChild(i).gameObject);
			}
			this.transformRoot.DetachChildren();
			this.select = -1;
			this.inputName.text = string.Empty;
			this.buttonSave.interactable = false;
			this.buttonLoad.interactable = false;
			this.buttonImport.interactable = false;
			this.buttonDelete.interactable = false;
			IEnumerable<string> files = Directory.GetFiles(UserData.Create("studio/voicelist"), "*.dat");
			if (VoiceRegistrationList.callback0 == null)
			{
				VoiceRegistrationList.callback0 = new Func<string, bool>(VoiceCtrl.CheckIdentifyingCode);
			}
			this.listPath = files.Where(VoiceRegistrationList.callback0).ToList<string>();
			this.dicNode.Clear();
			for (int j = 0; j < this.listPath.Count; j++)
			{
				GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.prefabNode);
				gameObject.transform.SetParent(this.transformRoot, false);
				StudioNode component = gameObject.GetComponent<StudioNode>();
				component.active = true;
				int no = j;
				component.addOnClick = delegate()
				{
					this.OnClickSelect(no);
				};
				component.text = VoiceCtrl.LoadListName(this.listPath[j]);
				this.dicNode.Add(j, component);
			}
		}

		// Token: 0x060023E5 RID: 9189 RVA: 0x000D7AF0 File Offset: 0x000D5CF0
		private void Awake()
		{
			this.buttonClose.onClick.AddListener(new UnityAction(this.OnClickClose));
			this.inputName.onEndEdit.AddListener(new UnityAction<string>(this.OnEndEditName));
			this.buttonSave.onClick.AddListener(new UnityAction(this.OnClickSave));
			this.buttonSave.interactable = false;
			this.buttonLoad.onClick.AddListener(new UnityAction(this.OnClickLoad));
			this.buttonImport.onClick.AddListener(new UnityAction(this.OnClickImport));
			this.buttonDelete.onClick.AddListener(new UnityAction(this.OnClickDelete));
		}

		// Token: 0x040024C3 RID: 9411
		[SerializeField]
		private Button buttonClose;

		// Token: 0x040024C4 RID: 9412
		[SerializeField]
		private InputField inputName;

		// Token: 0x040024C5 RID: 9413
		[SerializeField]
		private Button buttonSave;

		// Token: 0x040024C6 RID: 9414
		[SerializeField]
		private Button buttonLoad;

		// Token: 0x040024C7 RID: 9415
		[SerializeField]
		private Button buttonImport;

		// Token: 0x040024C8 RID: 9416
		[SerializeField]
		private Transform transformRoot;

		// Token: 0x040024C9 RID: 9417
		[SerializeField]
		private GameObject prefabNode;

		// Token: 0x040024CA RID: 9418
		[SerializeField]
		private Button buttonDelete;

		// Token: 0x040024CB RID: 9419
		[SerializeField]
		private Sprite spriteDelete;

		// Token: 0x040024CC RID: 9420
		[SerializeField]
		private VoiceControl voiceControl;

		// Token: 0x040024CE RID: 9422
		private List<string> listPath;

		// Token: 0x040024CF RID: 9423
		private Dictionary<int, StudioNode> dicNode = new Dictionary<int, StudioNode>();

		// Token: 0x040024D0 RID: 9424
		private int select = -1;

		// Token: 0x040024D1 RID: 9425
		[CompilerGenerated]
		private static Func<string, bool> callback0;
	}
}
